#include<bits/stdc++.h>
#define int long long
#define N 1000005
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int n,c;
int a[N],b[N];
int f[1005][1005];
int p,g[2][N];
const int inf=1e16;
void sub1(){
    for(int i=1;i<=n;i++) b[i]=a[i];
    sort(b+1,b+n+1);
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
            f[i][j]=inf;
    f[0][n]=0;
    for(int i=1;i<=n;i++){
        int mn=inf;
        for(int j=n;j>=1;j--){
            mn=min(mn,f[i-1][j]);
            f[i][j]=mn+(b[j]>=a[i]?b[j]-a[i]:c);
        }
    }
    int ans=inf;
    for(int i=1;i<=n;i++) ans=min(ans,f[n][i]);
    printf("%lld\n",ans);
}
void sub2(){
    int o=0;
    for(int i=0;i<=p;i++) g[0][i]=inf;
    g[0][p]=0;
    for(int i=1;i<=n;i++){
        o^=1;
        int mn=inf;
        for(int j=p;j>=0;j--){
            mn=min(mn,g[o^1][j]);
            g[o][j]=mn+(j>=a[i]?j-a[i]:c);
        }
    }
    int ans=inf;
    for(int i=0;i<=p;i++) ans=min(ans,g[o][i]);
    printf("%lld\n",ans);
}
void sub3(){
    int ans=n*c,sum=0;
    for(int i=1;i<=n;i++){
        sum+=a[i];
        ans=min(ans,i*a[i]-sum+(n-i)*c);
    }
    printf("%lld\n",ans);
}
signed main(){
    freopen("minimize.in","r",stdin);
    freopen("minimize.out","w",stdout);
    n=read();c=read();
    for(int i=1;i<=n;i++) a[i]=read();
    if(c==0){printf("0\n");return 0;}
    if(n<=1000){sub1();return 0;}
    for(int i=1;i<=n;i++) p=max(p,a[i]);
    if(p<=100){sub2();return 0;}
    sub3();
    return 0;
}